package psn.kiko.pojo;

import io.swagger.annotations.ApiModel;
import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import psn.kiko.constant.MessageConstant;
import psn.kiko.constant.ResponseCodeConstant;

/**
 * 业务操作结果
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@ApiModel(description="业务操作响应体")
public class Result<D>{
	/**
	 * 业务响应状态码：1-成功，0-失败
	 */
	@ApiModelProperty(required=true,value="业务响应状态码：1-成功，0-失败")
	private Integer code;
	/**
	 * 业务响应提示信息
	 */
	@ApiModelProperty(value="业务响应提示信息")
	private String msg;
	/**
	 * 业务响应数据
	 */
	@ApiModelProperty(value="业务响应数据")
	private D data;
	
	public static Result<?> success(){
		return Result.builder()
				.code(ResponseCodeConstant.BUSINESS_OPERATION_SUCCESS)
				.msg(MessageConstant.BUSINESS_OPERATION_SUCCESS)
				.build();
	}
	
	public static Result<?> success(String msg){
		return Result.builder()
				.code(ResponseCodeConstant.BUSINESS_OPERATION_SUCCESS)
				.msg(msg)
				.build();
	}
	
	public static <D> Result<?> success(D data){
		return Result.builder()
				.code(ResponseCodeConstant.BUSINESS_OPERATION_SUCCESS)
				.data(data)
				.msg(MessageConstant.BUSINESS_OPERATION_SUCCESS)
				.build();
	}
	
	public static <D> Result<?> success(String msg,D data){
		return Result.builder()
				.code(ResponseCodeConstant.BUSINESS_OPERATION_SUCCESS)
				.data(data)
				.msg(msg)
				.build();
	}
	
	public static Result<?> fail(){
		return Result.builder()
				.code(ResponseCodeConstant.BUSINESS_OPERATION_FAIL)
				.msg(MessageConstant.BUSINESS_OPERATION_FAIL)
				.build();
	}
	
	public static Result<?> fail(String msg){
		return Result.builder()
				.code(ResponseCodeConstant.BUSINESS_OPERATION_FAIL)
				.msg(msg)
				.build();
	}
	
	public static <D> Result<?> fail(D data){
		return Result.builder()
				.code(ResponseCodeConstant.BUSINESS_OPERATION_FAIL)
				.msg(MessageConstant.BUSINESS_OPERATION_FAIL)
				.data(data)
				.build();
	}
	
	public static <D> Result<?> fail(String msg,D data){
		return Result.builder()
				.code(ResponseCodeConstant.BUSINESS_OPERATION_FAIL)
				.data(data)
				.msg(msg)
				.build();
	}
}
